﻿using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using PlanningGIS.Framework;

namespace PlanningGIS.Cartographic
{
    /// <summary>
    /// 清除绘制的对象
    /// </summary>
    public class ClearGraphics : BaseCommand
    {
        /// <summary>
        /// 应用程序框架
        /// </summary>
        IApplication m_Application = null;

        /// <summary>
        /// 构造函数
        /// </summary>
        public ClearGraphics()
        {
            base.m_caption = "清除图形";
            base.m_toolTip = base.m_caption;
        }

        /// <summary>
        /// 创建按钮
        /// </summary>
        /// <param name="hook"></param>
        public override void OnCreate(object hook)
        {
            if (m_Application == null)
            {
                m_Application = hook as IApplication;
            }
        }

        /// <summary>
        /// 点击事件
        /// </summary>
        public override void OnClick()
        {
            if (m_Application == null || m_Application.Document == null) return;
            if (!(m_Application.Document is IMxDocument)) return;
            IGraphicsContainer pGraphicsContainer = (m_Application.Document as IMxDocument).ActiveView as IGraphicsContainer;
            pGraphicsContainer.DeleteAllElements();
            (m_Application.Document as IMxDocument).ActiveView.Refresh();
        }

        /// <summary>
        /// 图标
        /// </summary>
        public override int Bitmap
        {
            get
            {
                string bitmapResourceName = this.GetType().Namespace + ".Res." + this.GetType().Name + ".png";
                return new Bitmap(GetType().Assembly.GetManifestResourceStream(bitmapResourceName)).GetHbitmap().ToInt32();
            }
        }

        /// <summary>
        /// 是否可用
        /// </summary>
        public override bool Enabled
        {
            get
            {
                if (m_Application == null) return false;
                return (m_Application as IFramework).IsPageLayoutActive;
            }
        }
    }
}
